using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class ChucNang_LoaiNguoiDungRepository
	{
		public static List<ChucNang_LoaiNguoiDung> SelectAll()
		{
			return DataContext.Instance.ChucNang_LoaiNguoiDung.ToList();
		}

		public static ChucNang_LoaiNguoiDung SelectByID(int machucnangnguoidung)
		{
			return DataContext.Instance.ChucNang_LoaiNguoiDung.FirstOrDefault(item => item.MaCNLND == machucnangnguoidung );
		}

		public static bool Insert(ChucNang_LoaiNguoiDung obj)
		{
			try
			{
				DataContext.Instance.ChucNang_LoaiNguoiDung.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int machucnangnguoidung)
		{
			try
			{
				var delitem = DataContext.Instance.ChucNang_LoaiNguoiDung.FirstOrDefault(item => item.MaCNLND == machucnangnguoidung );
				DataContext.Instance.ChucNang_LoaiNguoiDung.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<ChucNang_LoaiNguoiDung> RetrieveByID(int machucnangnguoidung)
		{
			return (from item in DataContext.Instance.ChucNang_LoaiNguoiDung where  item.MaCNLND == machucnangnguoidung  select item).ToList();
		}

		public static List<ChucNang_LoaiNguoiDung> SelectByMaLoaiNguoiDung(int maloainguoidung)
		{
			var lstItem = (from item in DataContext.Instance.ChucNang_LoaiNguoiDung where item.MaLND == maloainguoidung select item).ToList();
			return lstItem;
		}

		public static List<ChucNang_LoaiNguoiDung> SelectByMaChucNang(int machucnang)
		{
			var lstItem = (from item in DataContext.Instance.ChucNang_LoaiNguoiDung where item.MaCN == machucnang select item).ToList();
			return lstItem;
		}

	}
}